package com.concurrent.aqslock.part9.rw;

/**
 *类说明：用内置锁来实现商品服务接口
 */
public class UseSynImpl implements GoodsService {
	
	private GoodsInfo goodsInfo;
	
	public UseSynImpl(GoodsInfo goodsInfo) {
		this.goodsInfo = goodsInfo;
	}

	@Override
	public synchronized GoodsInfo getNum() {
        try {
            Thread.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return this.goodsInfo;
	}

	@Override
	public synchronized void setNum(int number) {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        goodsInfo.changeNumber(number);

	}

}
